unit Class_Work_Doct;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TWorkDoct=class(TUniEngine)
  private
    FUnitLink: string;
    FWorkIdex: Integer;
    FDoctIdex: Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property UnitLink: string read FUnitLink write FUnitLink;
    property WorkIdex: Integer read FWorkIdex write FWorkIdex;
    property DoctIdex: Integer read FDoctIdex write FDoctIdex;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AWorkDoct:TWorkDoct):TWorkDoct;overload;        
    class procedure CopyIt(AWorkDoct:TWorkDoct;var Result:TWorkDoct);overload;       
  end;

implementation

{ TWorkDoct }
procedure TWorkDoct.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('WORK_IDEX').Value := WORKIDEX;
        ParamByName('DOCT_IDEX').Value := DOCTIDEX; 
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('WORK_IDEX').Value := WORKIDEX;
        ParamByName('DOCT_IDEX').Value := DOCTIDEX; 
      end;  
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('WORK_IDEX').Value := WORKIDEX;
        ParamByName('DOCT_IDEX').Value := DOCTIDEX; 
      end;  
    end;
  end;
end;

function TWorkDoct.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_WORK_DOCT',['UNIT_LINK',UNITLINK,'WORK_IDEX',WORKIDEX,'DOCT_IDEX',DOCTIDEX],AUniConnection);
end;

function TWorkDoct.GetNextIdex: Integer;
begin

end;

function TWorkDoct.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TWorkDoct.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_WORK_DOCT WHERE   UNIT_LINK=:UNIT_LINK AND WORK_IDEX=:WORK_IDEX AND DOCT_IDEX=:DOCT_IDEX';
end;

function TWorkDoct.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_WORK_DOCT'
         +'    ( UNIT_LINK, WORK_IDEX, DOCT_IDEX)'
         +'    VALUES'
         +'    (:UNIT_LINK,:WORK_IDEX,:DOCT_IDEX)';
end;

function TWorkDoct.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%D',[UNITLINK,WORKIDEX,DOCTIDEX]);
end;

function TWorkDoct.GetStrUpdate: string;
begin
  raise Exception.Create('CAN NOT SUPPORT GETSTRUPDATE METHOD.CAUSE ALL THIS TABLE FILEDS ARE PRIMARY KEY.')
end;

constructor TWorkDoct.Create;
begin

end;

destructor TWorkDoct.Destroy;
begin

  inherited;
end;

class function TWorkDoct.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TWorkDoct.Create;
  with TWorkDoct(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    WORKIDEX:=AUniQuery.FieldByName('WORK_IDEX').AsInteger;
    DOCTIDEX:=AUniQuery.FieldByName('DOCT_IDEX').AsInteger;
  end;  
end;

class procedure TWorkDoct.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TWorkDoct(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    WORKIDEX:=AUniQuery.FieldByName('WORK_IDEX').AsInteger;
    DOCTIDEX:=AUniQuery.FieldByName('DOCT_IDEX').AsInteger;
  end;  
end;

class function  TWorkDoct.CopyIt(AWorkDoct: TWorkDoct): TWorkDoct;
begin
  Result:=TWorkDoct.Create;
  TWorkDoct.CopyIt(AWorkDoct,Result)
end;

class procedure TWorkDoct.CopyIt(AWorkDoct:TWorkDoct;var Result:TWorkDoct);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=AWorkDoct.UNITLINK;
  Result.WORKIDEX:=AWorkDoct.WORKIDEX;
  Result.DOCTIDEX:=AWorkDoct.DOCTIDEX;
end;

end.

